const App = getApp()

Page({
    data:{
        id:'',
        info:[],
    },
    onLoad(options){
        var id=options.id
        this.setData({
            id:id
        })
        this.getOrdersInfo(id)
    },
    getOrdersInfo:function(id){
        var that=this
        var show=wx.showToast({
        title: '加载中',
        icon: 'loading',
        })
        App.HttpService.getOrdersInfo({
            id:id
        }).then(data=>{
            wx.hideToast()
            if(data.meat.code==0){
                that.setData({
                    info:data.info
                })
            }
        })
    },
    //联系客服
    callCustomService:function(){
        
        wx.makePhoneCall({
          phoneNumber: '18079137975',
        })
    },
    //回到首页
    goIndex:function(){
        wx.switchTab({
          url: '/pages/index/index',
        })
    },
     //确定收货
    confrimTake:function(e){
        var id=e.currentTarget.dataset.id
        var that=this
         wx.showModal({
            title: '温馨提示',
            content: '是否确定收货?',
            success: function(res) {
                if (res.confirm) {
                 wx.showToast({
                    title: '操作中...',
                    icon: 'loading',
                    duration: 20000
                    })
                App.HttpService.confirmTake({
                    id:id
                }).then(data=>{
                    wx.hideToast()
                    if(data.meat.code == 0){
                        wx.showToast({
                            title:'收货成功',
                            icon:'success',  
                        })
                        setTimeout(function(){
                            that.getOrdersInfo(that.data.id)
                        },1500)
                       
                    }
                })     
                }
            }
        })
    },
    showOrderBj:function(e){
  var type_=e.currentTarget.dataset.type
  var id=e.currentTarget.dataset.id
  if(id=='0'||id==''){
    wx.showToast({
      title: '暂无数据',
      icon: 'loading',
      duration: 1000
    })
    return
  }
  wx.navigateTo({
    url: '../../show/orders/index?id='+id+'&type='+type_,
  })

  },
     //微信支付
    payOrders:function(e){
         var that=this
         var id=e.currentTarget.dataset.id
        wx.showToast({
            title: '请稍后..',
            icon: 'loading',
            duration: 200000
        })
        wx.login({
            success: function(res){
                if(res.code){
                App.HttpService.getUserOpenid({
                code:res.code,
                id:id
                }).then(data=>{
                var success=("appId" in data)
                if(success==false){
                        wx.showToast({
                            title:data.data,
                            icon:'loading',
                            image:'../../../assets/images/error-icon.png',
                        })
                    }else{
                        wx.hideToast()
                        wx.requestPayment({
                            'timeStamp': data.timeStamp,
                            'nonceStr': data.nonceStr,
                            'package': data.package,
                            'signType': 'MD5',
                            'paySign': data.paySign,
                            success: function(res){
                                wx.showToast({
                                    title: '支付成功',
                                    icon: 'success',
                                    duration: 2000
                                })
                                setTimeout(function(){
                                    App.HttpService.editOrderStatus({
                                        id:id,
                                        status:1
                                    }).then(data=>{
                                        if(data.meat.code == 0){
                                            that.getOrdersInfo(id)
                                        }
                                    })
                                },2000)
                            },"fail":function(res){
                                that.getOrdersInfo(id)
                                wx.showToast({
                                    title: '支付失败',
                                    icon: 'loading',
                                    image:'../../assets/images/error-icon.png',
                                    duration: 2000
                                })
                                
                            }
                        })  
                    }
                
                })
                }else{
                wx.showToast({
                    title:'获取用户信息失败',
                    icon:'loading',
                    image:'../../assets/images/error.png',
                })
                }
            },
        })
    },  
})